package com.zuxia.service.impl;

import com.zuxia.dto.BookPageQueryDTO;
import com.zuxia.entity.Book;
import com.zuxia.mapper.BookMapper;
import com.zuxia.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class BookServiceImpl implements IBookService {
    /**
     * 自动装配BookMapper实例对象
     */
    @Autowired
    private BookMapper bookMapper;

    /**
     * 添加图书业务
     * @param book
     * @return
     */
    @Override
    public boolean addBook(Book book) {
        return bookMapper.insert(book) > 0;
    }

    /**
     * 修改图书业务
     * @param book
     * @return
     */
    @Override
    public boolean updateBook(Book book) {
        return bookMapper.updateById(book) > 0;
    }

    /**
     * 根据id删除图书业务
     * @param id
     * @return
     */
    @Override
    public boolean deleteBook(Integer id) {
        return bookMapper.deleteById(id) > 0;
    }

    /**
     * 根据id查询图书信息业务
     * @param id
     * @return
     */
    @Override
    public Book getBookById(int id) {
        return bookMapper.getById(id);
    }

    /**
     * 条件分页查询图书业务
     * @param bookPageQueryDTO
     * @return
     */
    @Override
    public List<Book> getAllBooks(BookPageQueryDTO bookPageQueryDTO) {
        return bookMapper.pageQuery(bookPageQueryDTO);
    }
}
